unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Vcl.ExtCtrls, Vcl.Samples.Spin, Vcl.ComCtrls, Vcl.Buttons;

type
  TForm1 = class(TForm)
    rg: TRadioGroup;
    od: TOpenDialog;
    sd: TSaveDialog;
    se: TSpinEdit;
    Button1: TButton;
    Panel2: TPanel;
    BitBtn20: TBitBtn;
    BitBtn21: TBitBtn;
    BitBtn22: TBitBtn;
    BitBtn23: TBitBtn;
    BitBtn24: TBitBtn;
    BitBtn25: TBitBtn;
    BitBtn26: TBitBtn;
    BitBtn27: TBitBtn;
    BitBtn28: TBitBtn;
    BitBtn29: TBitBtn;
    BitBtn30: TBitBtn;
    BitBtn31: TBitBtn;
    BitBtn32: TBitBtn;
    BitBtn33: TBitBtn;
    BitBtn34: TBitBtn;
    BitBtn35: TBitBtn;
    BitBtn36: TBitBtn;
    BitBtn37: TBitBtn;
    BitBtn38: TBitBtn;
    BitBtn39: TBitBtn;
    BitBtn40: TBitBtn;
    BitBtn41: TBitBtn;
    BitBtn42: TBitBtn;
    BitBtn43: TBitBtn;
    BitBtn44: TBitBtn;
    BitBtn45: TBitBtn;
    BitBtn46: TBitBtn;
    BitBtn47: TBitBtn;
    BitBtn48: TBitBtn;
    BitBtn49: TBitBtn;
    BitBtn50: TBitBtn;
    BitBtn51: TBitBtn;
    BitBtn52: TBitBtn;
    BitBtn53: TBitBtn;
    BitBtn54: TBitBtn;
    BitBtn55: TBitBtn;
    BitBtn56: TBitBtn;
    BitBtn57: TBitBtn;
    BitBtn58: TBitBtn;
    BitBtn59: TBitBtn;
    BitBtn60: TBitBtn;
    BitBtn61: TBitBtn;
    BitBtn62: TBitBtn;
    BitBtn63: TBitBtn;
    BitBtn64: TBitBtn;
    BitBtn65: TBitBtn;
    BitBtn66: TBitBtn;
    BitBtn67: TBitBtn;
    BitBtn68: TBitBtn;
    BitBtn69: TBitBtn;
    BitBtn70: TBitBtn;
    BitBtn71: TBitBtn;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    BitBtn5: TBitBtn;
    BitBtn6: TBitBtn;
    BitBtn7: TBitBtn;
    BitBtn8: TBitBtn;
    BitBtn9: TBitBtn;
    BitBtn10: TBitBtn;
    Panel1: TPanel;
    BitBtn11: TBitBtn;
    BitBtn12: TBitBtn;
    BitBtn13: TBitBtn;
    BitBtn14: TBitBtn;
    BitBtn15: TBitBtn;
    BitBtn16: TBitBtn;
    BitBtn17: TBitBtn;
    BitBtn18: TBitBtn;
    BitBtn19: TBitBtn;
    BitBtn72: TBitBtn;
    procedure Button1Click(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure FormCreate(Sender: TObject);
    procedure seChange(Sender: TObject);
    procedure rgClick(Sender: TObject);
    procedure seKeyPress(Sender: TObject; var Key: Char);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure Button1KeyPress(Sender: TObject; var Key: Char);
    procedure Button1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure BitBtn20Click(Sender: TObject);
    procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure BitBtn1KeyPress(Sender: TObject; var Key: Char);
    procedure BitBtn1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    procedure StartRecord;
    procedure StartPlay;
    { Public declarations }
  published
  end;

var
  Form1: TForm1;

implementation

uses u;

{$R *.dfm}

Function l(o: Byte; n: Byte):word;
begin
 if n<>0 then
 if o=4 then
  begin
   case n of
   1:l:=2093;
   2:l:=2217;
   3:l:=2349;
   4:l:=2489;
   5:l:=2637;
   6:l:=2794;
   7:l:=2960;
   8:l:=3136;
   9:l:=3322;
   10:l:=3520;
   11:l:=3729;
   12:l:=3951;
   end
  end
 else
 if o < 4 then 
 begin
 l:=round(l(o+1,n)/2);
 end
 else
 begin
 l:=l(o-1,n) * 2 ;
 end
end;


function TagSplit(tag: Word): Word;
var
  n, o: Byte;
begin
  o := tag div 12;
  n := tag mod 12 + 1;
  Result := l(o, n);
end;

var
  convertionTable : array [12..52] of Word = (
    16, 65, 90, 83, 88,    67, 70, 86, 71, 66, 72, 78,
    77, 75, 188, 76, 190,  191, 222, 81, 50, 87, 51, 69,
    82, 53, 84, 54, 89,    85, 56, 73, 57, 79, 48, 80,
    219, 187, 221, 8, 220);
function KeyProcess(key: word): Word;
var
  i: Word;
begin
  for i := Low(convertionTable) to High(convertionTable) do
    if convertionTable[i] = key then begin
      Sound(TagSplit(i), 200);
      Exit;
    end;
  //Sound(TagSplit(0), 200);
end;

procedure TForm1.BitBtn1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  //ShowMessage(IntToStr(key));
  KeyProcess(Key);
end;

procedure TForm1.BitBtn1KeyPress(Sender: TObject; var Key: Char);
begin
  //
end;

procedure TForm1.BitBtn20Click(Sender: TObject);
begin
  Sound(TagSplit(TBitBtn(Sender).Tag), 500);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 Sound(440,1000);

end;

procedure TForm1.Button1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 // ShowMessage('asdf1');
end;

procedure TForm1.Button1KeyPress(Sender: TObject; var Key: Char);
begin
    //sb.SimpleText := KeyProcess(Key)
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  //Init;

  //se.Value := GetDuration;

end;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  //ShowMessage('asdf');
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
//ShowMessage('asdf');
  //sb.SimpleText := KeyProcess(Key)
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
//   Sound(X + 500, 1000);
end;

procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
   Sound(X + 500, 100);
end;

procedure TForm1.rgClick(Sender: TObject);
begin
 { case rg.ItemIndex of
  0: Stop;
  1: StartRecord;
  2: StartPlay;
  end;   }
end;

procedure TForm1.seChange(Sender: TObject);
begin
  //SetDuration(se.Value);
end;

procedure TForm1.seKeyPress(Sender: TObject; var Key: Char);
begin
  ShowMessage('asdf');
end;

procedure TForm1.StartPlay;
begin
  if od.Execute() then begin
    //PlayFile(od.FileName);
  end;

end;

procedure TForm1.StartRecord;
begin
  if sd.Execute() then begin
    //RecordFile(sd.FileName);
  end;
end;

end.
